package com.hzvtc.bosswang.managecommon.utils;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.AntPathMatcher;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginCheckFilter implements Filter {



    public RedisTemplate redisTemplate;
    public static final AntPathMatcher ANT_PATH_MATCHER=new AntPathMatcher();
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

        HttpServletRequest httpServletRequest=(HttpServletRequest) request;
        HttpServletResponse httpServletResponse=(HttpServletResponse) response;

        String requestURI=httpServletRequest.getRequestURI();

        String[] urls={
                "/**"
        };
        if (!check(urls,requestURI)){
            System.out.println("不需要拦截"+requestURI);
            chain.doFilter(request,response);
            return;
        }

//        redisTemplate.opsForValue().get();

    }


    // JWT Token

    public boolean check(String[] urls,String requestURI){
        for (String url : urls){
            if (ANT_PATH_MATCHER.match(url,requestURI)){
                return true;
            }
        }
        return false;
    }
}
